package cn.jjzd.info.controller;

import cn.jjzd.info.service.InfoHtmlService;
import cn.jjzd.info.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
public class InfoController {

    @Autowired
    private InfoService infoService;

    @Autowired
    private InfoHtmlService infoHtmlService;

    /*@GetMapping("list")
    public ResponseEntity<Map<String,List<SysArticleBo>>> queryArticleListByCids(@RequestParam("cids") List<Long> cids){

        Map<String,List<SysArticleBo>> map = infoService.queryArticleListByCids(cids);
        if(map == null || CollectionUtils.isEmpty(map)){
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(map);
    }*/

    /**
     * 根据资讯ID生成静态页面
     * @param id
     * @param model
     * @return
     */
    @GetMapping("info/{id}.html")
    public String toDetailPage(@PathVariable("id")Long id, Model model){
        Map<String,Object> map = this.infoService.loadDetailData(id);
        model.addAllAttributes(map);
        infoHtmlService.createHtml(id,1);
        return "detailsPage";
    }

    /**
     * 根据分类ID生成静态页面
     * @param cid
     * @param model
     * @return
     */
    @GetMapping("info/category/{cid}.html")
    public String toMorePage(@PathVariable("cid")Long cid, Model model){
        Map<String,Object> map = this.infoService.loadMoreData(cid);
        model.addAllAttributes(map);
        infoHtmlService.createHtml(cid,2);
        return "morePage";
    }
}
